import { RequestOderList,RequestRemoveOderList } from "@/api/oderlist";
import { ref,type Ref,onMounted} from "vue";
import type { IOderlist,Ilist } from "@/types/types";
import { userStore } from "@/stores/user";
import type { ICount } from '@/types/home'
import { Toast } from "vant";


//查询订单
export const useOderlist =()=>{
    const count = userStore()
    let userinfoId:Ref<number>= ref(0)
    let show:boolean = false
const oderlist:Ref<Array<IOderlist>> = ref([])//订单

if(!count.count){
     show = !show
}


const getOderlist = async (userId:number) => {
    const data = await RequestOderList(userId)
    const {resultCode,resultInfo} = data   
        if(resultCode===1){
             oderlist.value = resultInfo          
        }
      }
const getId=()=>{
        userinfoId.value = count.getCount.uid
        const num = userinfoId.value
        getOderlist(num)
 }
 const deloderlist = (i:number) =>{
      oderlist.value.splice(i,1)
 }
onMounted(()=>{
    getId()
})
      return {userinfoId,oderlist,show,deloderlist}
}



//取消订单
export const useRemoveorder=()=>{
    
    let num:number = 0
const getRemoveOrder =async(orderNum:number)=>{
    
    const data = await RequestRemoveOderList(orderNum)
    const {resultCode,resultInfo} = data
   
    if(resultCode===1){
        
        Toast(resultInfo);
    }
}
const bindOrder_num = (ordernum:string)=>{
    
     num = Number(ordernum)
   
   getRemoveOrder(num)
 }




return {bindOrder_num,}

}
